package com.padakeji.android.tumou.present;

import com.baidu.location.BDLocation;
import com.padakeji.android.tumou.bean.News;
import com.padakeji.android.tumou.model.LocationModel;
import com.padakeji.android.tumou.model.NewsModel;
import com.padakeji.android.tumou.view.HomeView;

import java.util.List;

/**
 * Created by AtanL on 2015/9/8.
 */
public class HomePresent {

    private HomeView v;

    private LocationModel locationModel;
    private NewsModel newsModel;

    public HomePresent(HomeView homeView) {
        this.v = homeView;
        this.locationModel = new LocationModel(new LocationModel.OnLocateListener() {
            @Override
            public void onLocate(BDLocation location) {
                renderMyLocation(location);
            }
        });
        this.newsModel = new NewsModel();
        newsModel.setOnNewsListener(new NewsModel.OnNewsListListener() {
            @Override
            public void onNewsList(List<News> news) {
                renderNews(news);
            }
        });
    }

    public void locate() {
        locationModel.locate();
    }

    public void loadNewsData(double lat, double lng) {
        newsModel.loadNews(lat, lng);
    }

    public void createNews(News news) {
        newsModel.createNews(news);
    }

    private void renderMyLocation(BDLocation location) {
        double lat = location.getLatitude();
        double lng = location.getLongitude();
        v.renderMyLocation(lat, lng);
    }

    private void renderNews(List<News> news) {
        v.renderNews(news);
    }


}
